/*字符串不能为空 */
function IsEmpty (string) 
{
	var str = string.replace(/\s+/g,"");
	if (str == '') return false;
	else return str;
}
/*是否是用户名，前台注册是用到*/
function IsUserName (string){
	var number = IsEmpty(string);
	if (number == false) return false;
	if(/^[a-zA-Z]{1}[a-zA-Z0-9]{1,}$/.test(string)) return true;
	else return false;	
}
/*会员号，9位的数字开始*/
function IsJointCard(string){
	var number = IsEmpty(string);
	if (number == false) return false;
	if(/^[0-9]{9}$/.test(string)) return true;
	else return false;	
}
/*字符串是否是数字 */
function IsNumber (string){
	var number = IsEmpty(string);
	if (number == false) return false;
	if(/^[0-9]+$/.test(number)) return true;
	else return false;	
}
/*字符串是否是姓名 */
function IsName(string){
	if(string==""){
		return true;
	}
	if(/([^\u4e00-\u9fa5])/.test(string)||string.length>10||string.length<2){
	}else{
		return true;
	}
	if(/^[a-zA-Z.\s]{3,}$/.test(string)){
		return true;
	}
	return false;
}
//出现蒙层效果,后期可能要改动
function openDiv(c,t,w,h){
if(typeof(t)!='string'){t='提示信息';}//默认宽
if(typeof(w)!='string'){w=300;}//默认宽
if(typeof(h)!='string'){h=200;}//默认高
    $.nyroModalManual({
      closeButton:'',
      content: "<div class='act-e' style='border:3px;background:#fff;solid #414141;height:"+h+"px;width:"+w+"px;'><div class='t'><h2>"+t+"</h2><span class='nyroModalClose' id='nyroModalClose'>关闭</span></div>"+c+"</div>",
      minWidth: w, // Minimum width
     minHeight: h, // Minimum height
     bgColor:'#404040'
 });
}
/* 手机号码验证  */
function IsMobile (string) 
{
	var mobile = IsEmpty(string);
	if (mobile == false) return false;
	//var pattern = /^(?:13\d|15[89])-?\d{5}(\d{3}|\*{3})$/;
	var pattern = /^0{0,1}(13|15|18)[0-9]{9}$/; 
	if(pattern.test(mobile)) return true;
	else{
	alert("手机号码非法，请输入真实的号码。");
	 return false;
	 }
}

/* 手机号码验证,无alert  */
function IsMobileNoAlert (string) 
{
	var mobile = IsEmpty(string);
	if (mobile == false) return false;
	if(/^0{0,1}(13|15|18)[0-9]{9}$/.test(mobile)) return true;
	else{
	 return false;
	 }
}


/*号码验证包括手机号、电话号和传真号*/
function isTel(str){
	var pattern =/^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/;
	if(str!="")   
        {   
            if(!pattern.exec(str))   
            {   
			return false;
            }
        return true;       
        }   
}  

function exist(id) {
    var s = document.getElementById(id);
    if(s)  return true;
    else  return false;
}

/*是否是移动支持的号段*/
function Mobile (string) 
{
	var mobile = IsEmpty(string);
	if (mobile == false) return false;
	var pattern = /^0{0,1}(13[4-9]|15[7-9]|15[0-2]|18[7-8]|182)[0-9]{8}$/; 
	if(pattern.test(mobile)) return true;
	else return false;
}

/*Email格式验证 */
function IsEmail (string) 
{
	var email = IsEmpty(string);
	if (email == false) return false;
	var patrn = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	if(patrn.test(email) == false) return false;
	else return true;
}

/*日期格式*/
function DateTime (string)
{
	var datime = IsEmpty(string);
	if (datime == false) return false;
    if (/^[1-2][0-9]{3}-[0-9]{1,2}-[0-9]{1,2}/.test(datime) == false)  return false;
    var rece = new Array();
	   rece = datime.split("-");
    if (parseInt(rece[0]) % 4 == 0 || (parseInt(rece[0]) % 100 !== 0 && parseInt(rece[0]) % 4 == 0)) {
        ereg =/^[1-2][0-9]{3}-((01|03|05|07|08|1|3|5|7|8|10|12)-((0|)[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|4|6|9|11)-((0|)[1-9]|[1-2][0-9]|30)|(02|2)-((0|)[1-9]|[1-2][0-9]))$/;
    } else {
        ereg= /^[1-2][0-9]{3}-((01|03|05|07|08|1|3|5|7|8|10|12)-((0|)[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|4|6|9|11)-((0|)[1-9]|[1-2][0-9]|30)|(02|2)-((0|)[1-9]|1[0-9]|2[0-8]))$/;   
    }
    if (ereg.test(datime) == false)  return false;
    return true;
	
}

/*日期验证，string1在string2之前*/
function ComDate (string1, string2) 
{
	if (DateTime(string1) == false) return false;
	if (DateTime(string2) == false) return false;
	var date1 = string1.replace(/\s+/g,"");
	var date2 = string2.replace(/\s+/g,"");
	var tmp1 = date1.split("-");
	var tmp2 = date2.split("-");
	var t1 = new Date(tmp1[0], tmp1[1], tmp1[2]);
	var t2 = new Date(tmp2[0], tmp2[1], tmp2[2]);
	var ft = t1.getTime() - t2.getTime() ;
	if (ft < 0) return 1;
	else if (ft == 0) return 2;
	else return 3;
}

/*姓名是否含有特殊符号 */
function isOtherName (strname) 
{
	var GuestName = IsEmpty(strname);
	if (GuestName == false) return false;
	var ErrStr;
	var ErrChar;
	var ArryErrStr;	
	ErrChar="!@#$%^&*()_+|-=\\~`;'[]{}\"':,;.<>?～！@#￥％^&×（）……＋|－＝、〔〕｛｝：“；‘《》？，。、0123456789";
	ErrStr="虚拟,傻冒,先生,小姐,代订,你好,哈哈,服务,孙子,龟儿子";
	
	ArryErrStr = ErrStr.split(",");
	
	for(var k=0;k<GuestName.length;k++){ //是否含有非法字符
		if(ErrChar.indexOf(GuestName.charAt(k))>-1) return false;
	}
	
	if ( ErrStr!=null && ErrStr!="" ){ //是否含有非法字符串
		for (k=0; k<ArryErrStr.length; k++){
			if (GuestName.indexOf(ArryErrStr[k])>-1) return false;
		}
	}
	return true;
}

/*姓名是否包含中文字符*/
function CheckCnStr(name)
{
    var str = IsEmpty(name);
    if (str == false) return false;
	var filter = /[^\x00-\xff]/gi;
    if (filter.test(str)) return true;
    return false;
}

/*验证是否全部包含中文字符*/
function CheckAllCnStr(name)
{
    var str = IsEmpty(name);
    if (str == false) return false;
	var filter = /[^\u4e00-\u9fa5]/;
    if (!filter.test(str)) return true;
    return false;
}

function CheckEnStr(name)
{
	var str = IsEmpty(name);
	if (str == false) return false;
    var filter = /^[a-zA-Z\/]+$/;
    if (filter.test(str)) return true;
    return false;
}

/*页面停留时间超时*/
pageOpen = new   Date(); 
function   bye()
{  
	 pageClose = new Date();  
	 hours = (pageClose.getHours() - pageOpen.getHours());  
	 minutes = (pageClose.getMinutes() - pageOpen.getMinutes());  
	 seconds = (pageClose.getSeconds() - pageOpen.getSeconds());  
	 time = (seconds + (minutes * 60) + (hours * 60 * 60));  
	 if (time > 7200) return true;
 	 else return false;
 }

/*由身份证号、日期(2010-3-23)验证年龄
 * 成人大于12岁，返回1
 * 儿童大于2岁小于12岁，返回2
 * 婴儿小于两岁，返回3
 **/
function NumberCheckYearOld (idnum, takeoff)
{
	var idnumber = IsEmpty(idnum);
	if (idnumber == false) return false;
	var outdate = IsEmpty(takeoff);
	if (outdate == false) return false;
	var length = idnumber.length;
	if (length == 18)
	{
		var year = idnumber.substr(6,4);
		var month = idnumber.substr(10,2);
		var day = idnumber.substr(12,2);
	}
	if (length == 15)
	{
		var year = '';
		var month = idnumber.substr(8,2);
		var day = idnumber.substr(10,2);
		var test = new Array(996,997,998,999);
		var card_3 = idnumber.substr(12, 3);
		for (var i = 0; i < 4; i++)
		{
			if (card_3 == test[i]) year = '18' + idnumber.substr(6,2);
		}
		if (year == '') year = '19' + idnumber.substr(6,2);
	}
	var tmp = outdate.split('-');
	var age = tmp[0] - year;
	if ((month == (tmp[1] + 1)) && (day <= parseInt(tmp[2]))) age = age; 
	else if (month <= tmp[1]) age = age;
	else age = age - 1; 
	if (age < 2) return 3;
	else if (age < 12) return 2;
	else return 1;
}

/*由出生日期、日期(2010-3-23)验证年龄
 * 成人大于12岁，返回1
 * 儿童大于2岁小于12岁，返回2
 * 婴儿小于两岁，返回3
 **/
function BirthdayCheckYearOld (birthday, takeoff)
{
	var birth = birthday.split('-');
	var tmp = outdate.split('-');
	var age = tmp[0] - birth[0];
	if ((birth[1] == (tmp[1] + 1)) && (birth[2] <= parseInt(tmp[2]))) age = age; 
	else if (birth[1] <= tmp[1]) age = age;
	else age = age - 1; 
	if (age < 2) return 3;
	else if (age < 12) return 2;
	else return 1;
}

function CheckPID (type, number, id) {
	var P_type =  type;
	var P_num = number.replace(/\s+/g,"");
	if (P_type == "none" || P_type == "" || P_type == "None") {
		$("#orderInfo_memberInfoHis_paperType").after(errMsg("请选择证件类型"));
		return false;
	}
	if (P_num.length < 2 || P_num.length > 20) {
		$("#orderInfo_memberInfoHis_paperId").after(errMsg("请正确输入证件号码"));
		//$("#"+id).focus();
		return false;
	}
	if (P_type == "0002100001") {
		if(DocumentNum(number) == false){
			$("#orderInfo_memberInfoHis_paperId").after(errMsg("请正确输入身份证号码"));
			return false;
		}else{
			$("#orderInfo_memberInfoHis_paperId").next().remove();
		}
	}else{
		if(DocumentNum4Others(number) == false){
			$("#orderInfo_memberInfoHis_paperId").after(errMsg("请输入正确的证件号码"));
			return false;
		}else{
			$("#orderInfo_memberInfoHis_paperId").next().remove();
		}
	}
	return true;
}
function tirmAll(str){
	return str.replace(/^\s*/, "").replace(/\s*$/, "");
}

/*

function checkIdcard(idcard){

var area={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"}

var idcard,Y,JYM;
var S,M;
var idcard_array = new Array();
idcard_array = idcard.split("");
//地区检验
if(area[parseInt(idcard.substr(0,2))]==null) return 4;
//身份号码位数及格式检验
switch(idcard.length){
case 15:
if ( (parseInt(idcard.substr(6,2))+1900) % 4 == 0 || ((parseInt(idcard.substr(6,2))+1900) % 100 == 0 && (parseInt(idcard.substr(6,2))+1900) % 4 == 0 )){
ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2] [0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9])) [0-9]{3}$/;//测试出生日期的合法性
} else {
ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2] [0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2] [0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/;//测试出生日期的合法性
}
if(ereg.test(idcard)) return 0;
else return 2;
break;
case 18:
//18位身份号码检测
//出生日期的合法性检查
//闰年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11) (0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))
//平年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11) (0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))
if ( parseInt(idcard.substr(6,4)) % 4 == 0 || (parseInt(idcard.substr(6,4)) % 100 == 0 && parseInt(idcard.substr(6,4))%4 == 0 )){
ereg=/^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$/;//闰年出生日期的合法性正则表达式
} else {
ereg=/^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$/;//平年出生日期的合法性正则表达式
}
if(ereg.test(idcard)){//测试出生日期的合法性
//计算校验位
S = (parseInt(idcard_array[0]) + parseInt(idcard_array[10])) * 7
+ (parseInt(idcard_array[1]) + parseInt(idcard_array[11])) * 9
+ (parseInt(idcard_array[2]) + parseInt(idcard_array[12])) * 10
+ (parseInt(idcard_array[3]) + parseInt(idcard_array[13])) * 5
+ (parseInt(idcard_array[4]) + parseInt(idcard_array[14])) * 8
+ (parseInt(idcard_array[5]) + parseInt(idcard_array[15])) * 4
+ (parseInt(idcard_array[6]) + parseInt(idcard_array[16])) * 2
+ parseInt(idcard_array[7]) * 1
+ parseInt(idcard_array[8]) * 6
+ parseInt(idcard_array[9]) * 3 ;
Y = S % 11;
M = "F";
JYM = "10X98765432";
M = JYM.substr(Y,1);//判断校验位
if(M == idcard_array[17]) return 0; //检测ID的校验位
else return 3;
}
else return 2;
break;
default:
return 1;
break;
}
}*/
/*
        function CheckForm(idd)
        {

        var Errors=new Array(
"验证通过!",
"身份证号码位数不对!",
"身份证号码出生日期超出范围或含有非法字符!",
"身份证号码校验错误!",
"身份证地区非法!"
);
        var result=checkIdcard(idd);
        if(result!=0)
        {
        alert(Errors[result]);
                document.getElementById("txt_sfzmhm").focus();
                return false;       
        }       
            if(document.getElementById("txt_djzsxxdz").value=="")
            {
                alert('请输入你的登记住所详细地址！');
                document.getElementById("txt_djzsxxdz").focus();
                return false;
            }
            return true;
        }
*/
//================================================
//地区选择
function RemoveAllOption(obj)
{
var len = obj.length-1;
for(var i=len; i>=0; i--)
{
     obj.options.remove(i);
}
}
function AddEmptyOption(obj)
{
   obj.options.add(new Option("",""));
}
function FirstChangeOption1(ele,first,second,field)
{
RemoveAllOption(second);
second.options.add(new Option(first.options[first.selectedIndex].text,""));
var TempOptionStr;
    var SkillCode = field.value;
    var currentValue = first.value;
    if (currentValue.length >= 2){
        var arrValue = SkillCode.split(";");
        for (var i=0;i<arrValue.length;i++){
            var arrOneValue = arrValue[i].split(",");
            if (currentValue.substr(0,2) == arrOneValue[0].substr(0,2)) {    //查找到合适的项目
             if( arrOneValue[0].length >2 && arrOneValue[0] != currentValue)
             {
                    TempOptionStr= '　'+arrOneValue[1];
                    second.options.add(new Option(TempOptionStr,arrOneValue[0]));
             }
            }
        }
    }
   if (second.options.length <= 1) {
   second.style.display='none'; document.getElementById(ele).value = first.value ;
   }
    else second.style.display=''; }
function FirstChangeOption2(ele,first,second,third,field)
{
RemoveAllOption(second);
second.options.add(new Option(first.options[first.selectedIndex].text,"")); RemoveAllOption(third);
AddEmptyOption(third);
var TempOptionStr;
    var SkillCode = field.value;
    var currentValue = first.value;
    if (currentValue.length >= 2){
        var arrValue = SkillCode.split(";");
        for (var i=0;i<arrValue.length;i++){
            var arrOneValue = arrValue[i].split(",");
            if (currentValue.substr(0,2) == arrOneValue[0].substr(0,2)) {    //查找到合适的项目
                var IsZero = true;
                var ssub = arrOneValue[0].substr(4);
                for(var j=0; j<ssub.length;j++)
                {
                    if(ssub.substring(j,j+1) != "0")
                    {
                       IsZero = false;
                       break;
                    }
                }
             if(IsZero && arrOneValue[0]!=currentValue)
             {
                   TempOptionStr= '　'+arrOneValue[1];
                   second.options.add(new Option(TempOptionStr,arrOneValue[0]));
             }
            }
        }
    }
document.getElementById(ele).value = first.value;

if (second.options.length <= 1) second.style.display='none'; else second.style.display='';
if (third.options.length <= 1) third.style.display='none'; else third.style.display=''; }
function SecondChangeOption(ele,second,third,field)
{
RemoveAllOption(third);
third.options.add(new Option(second.options[second.selectedIndex].text.replace('　',''),""));
    var TempOptionStr;
    var SkillCode = field.value;
    var currentValue = second.value;
    if (currentValue.length!=0){
        var arrValue = SkillCode.split(";");
        for (var i=0;i<arrValue.length;i++){
            var arrOneValue = arrValue[i].split(",");
            if (arrOneValue[0].length>4 && arrOneValue[0] != currentValue && currentValue.substring(0,4) == arrOneValue[0].substr(0,4)) {    //查找到合适的项目
                TempOptionStr= '　'+arrOneValue[1];
                third.options.add(new Option(TempOptionStr,arrOneValue[0]));
            }
        }
    }
document.getElementById(ele).value = second.value;

if (third.options.length <= 1) third.style.display='none'; else third.style.display=''; }
function ThirdChangeOption(ele,third)
{
   document.getElementById(ele).value = third.value ;

  
}